home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
source
/
snip9503
/
round.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-14
|
833b
|
49 lines
/*
** rounding macros by Dave Knapp, Thad Smith, Jon Strayer, & Bob Stout
*/
#include <math.h>
#if __cplusplus
/*
** Safe C++ inline versions
*/
/* round to integer */
inline int iround(double x)
{
return (int)floor(x + ((x >= 0) ? 0.5 : -0.5));
}
/* round number n to d decimal points */
inline double fround(double n, unsigned d)
{
return floor(n * pow(10., d) + .5) / pow(10., d);
}
#else
/*
** NOTE: These C macro versions are unsafe since arguments are referenced
** more than once.
**
** Avoid using these with expression arguments to be safe.
*/
/*
** round to integer
*/
#define iround(x) floor((x) + ((x) >= 0 ? 0.5 : -0.5))
/*
** round number n to d decimal points
*/
#define fround(n,d) (floor((n)*pow(10.,(d))+.5)/pow(10.,(d)))
#endif